package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;

import com.cloudsigns.factorymanager2.engineering.bean.RegionBean;

import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/5/5.
 */

public class RegionListAdapter extends BaseAdapter {
    private Context context;
    private List<RegionBean> datas = new ArrayList<RegionBean>();
    private LayoutInflater inflater;
    private ItemClickListener clickListener;
    private String tag = "";


    public RegionListAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;

    }

    public void setData(List<RegionBean> list) {

        if (null != list) {
            this.datas.clear();
            this.datas.addAll(list);
        }

    }

    public void setItemClick(ItemClickListener clickListener) {
        this.clickListener = clickListener;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public RegionBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_media_region_list_lv, null);
            holder.tv_region_name = convertView.findViewById(R.id.tv_region_name);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        RegionBean bean = datas.get(position);
        holder.tv_region_name.setText(bean.getRegionName());


        return convertView;
    }

    private class ViewHolder {
        private TextView tv_region_name;

    }
}
